home *** CD-ROM | disk | FTP | other *** search
/ Look Around: Celtic Ireland / Look Around: Celtic Ireland.iso / main.dxr / 00023_Channel Volume Slider.ls < prev    next >
Encoding:
Text File  |  2003-04-14  |  5.5 KB  |  133 lines

  1. property SoundChannel, constraintsprite, initialvolume, spriteNum, mySprite, myActiveFlag, myDirection, mybounds, myclickoffset, plastvol
  2.  
  3. on beginSprite me
  4.   mySprite = sprite(spriteNum)
  5.   myActiveFlag = 0
  6.   inlist = me.insidespritelist(spriteNum)
  7.   if getPos(inlist, constraintsprite) = 0 then
  8.     constraintsprite = 0
  9.   end if
  10.   if constraintsprite = 0 then
  11.     boundrect = (the stage).rect
  12.     boundrect = offset(boundrect, -boundrect.left, -boundrect.top)
  13.   else
  14.     boundrect = sprite(constraintsprite).rect
  15.   end if
  16.   boundwidth = boundrect.width
  17.   boundheight = boundrect.height
  18.   if boundwidth > boundheight then
  19.     mybounds = [#min: boundrect.left + mySprite.locH - mySprite.left, #max: boundrect.right + mySprite.locH - mySprite.right]
  20.     mybounds[#range] = mybounds.max - mybounds.min
  21.     myDirection = #horizontal
  22.   else
  23.     mybounds = [#min: boundrect.top + mySprite.locV - mySprite.top, #max: boundrect.bottom + mySprite.locV - mySprite.bottom]
  24.     mybounds[#range] = mybounds.max - mybounds.min
  25.     myDirection = #vertical
  26.   end if
  27.   sound(SoundChannel).volume = initialvolume
  28.   plastvol = sound(SoundChannel).volume
  29.   newLoc = mybounds.range * initialvolume / 255
  30.   case myDirection of
  31.     #horizontal:
  32.       mySprite.locH = mybounds.min + newLoc
  33.     #vertical:
  34.       mySprite.locV = mybounds.max - newLoc
  35.   end case
  36. end
  37.  
  38. on mouseUpOutSide me
  39.   myActiveFlag = 0
  40. end
  41.  
  42. on mouseDown me
  43.   myclickoffset = the clickLoc - sprite(spriteNum).loc
  44.   myActiveFlag = 1
  45. end
  46.  
  47. on mouseUp me
  48.   myActiveFlag = 0
  49. end
  50.  
  51. on prepareFrame me
  52.   if myActiveFlag then
  53.     case myDirection of
  54.       #horizontal:
  55.         newLoc = (the mouseLoc).locH - myclickoffset.locH
  56.       #vertical:
  57.         newLoc = (the mouseLoc).locV - myclickoffset.locV
  58.     end case
  59.     if newLoc < mybounds.min then
  60.       newLoc = mybounds.min
  61.     else
  62.       if newLoc > mybounds.max then
  63.         newLoc = mybounds.max
  64.       end if
  65.     end if
  66.     case myDirection of
  67.       #horizontal:
  68.         mySprite.locH = newLoc
  69.       #vertical:
  70.         mySprite.locV = newLoc
  71.     end case
  72.   end if
  73.   case myDirection of
  74.     #horizontal:
  75.       offsetloc = mySprite.locH - mybounds.min
  76.     #vertical:
  77.       offsetloc = mybounds.max - mySprite.locV
  78.   end case
  79.   if myActiveFlag then
  80.     sound(SoundChannel).volume = 255 * offsetloc / mybounds.range
  81.   else
  82.     if sound(SoundChannel).volume <> plastvol then
  83.       newLoc = mybounds.range * sound(SoundChannel).volume / 255
  84.       case myDirection of
  85.         #horizontal:
  86.           mySprite.locH = mybounds.min + newLoc
  87.         #vertical:
  88.           mySprite.locV = mybounds.max - newLoc
  89.       end case
  90.     end if
  91.   end if
  92.   plastvol = sound(SoundChannel).volume
  93. end
  94.  
  95. on insidespritelist me, whichsprite
  96.   spritelist = [0]
  97.   thisSprite = sprite(whichsprite)
  98.   repeat with i = 1 to whichsprite - 1
  99.     case sprite(i).member.type of
  100.       #animGif, #bitmap, #picture, #quickTimeMedia, #digitalVideo, #shape, #field, #filmLoop, #flash, #text, #movie, #vectorShape:
  101.         if ((sprite(i).left < thisSprite.left) and (sprite(i).right > thisSprite.right)) or ((sprite(i).top < thisSprite.top) and (sprite(i).bottom > thisSprite.bottom)) then
  102.           spritelist.add(i)
  103.         end if
  104.     end case
  105.   end repeat
  106.   return spritelist
  107. end
  108.  
  109. on isOKToAttach me, aSpriteType, aSpriteNum
  110.   isOK = 0
  111.   case aSpriteType of
  112.     #graphic:
  113.       isOK = 1
  114.   end case
  115.   return isOK
  116. end
  117.  
  118. on getPropertyDescriptionList me
  119.   props = [:]
  120.   props[#SoundChannel] = [#comment: "Sound channel:", #format: #integer, #default: 1, #range: [1, 2, 3, 4, 5, 6, 7, 8]]
  121.   props[#constraintsprite] = [#comment: "Constraining sprite (0 = the stage):", #format: #integer, #default: 0, #range: me.insidespritelist(the currentSpriteNum)]
  122.   props[#initialvolume] = [#comment: "Initial sound volume:", #format: #integer, #default: 255, #range: [#min: 0, #max: 255]]
  123.   return props
  124. end
  125.  
  126. on getBehaviorTooltip me
  127.   return "Turns sprite into a sliding 'thumb' for sound volume control."
  128. end
  129.  
  130. on getBehaviorDescription me
  131.   return "CHANNEL VOLUME SLIDER" & RETURN & RETURN & "Drop this behavior onto a graphic sprite to turn it into a sliding 'thumb' that controls the volume of a sound." & RETURN & RETURN & "Select the sound channel that the slider will control, the sprite that defines the movement of the slider, and the starting volume of the sound." & RETURN & RETURN & "This behavior can control sound channels 1 to 8 (multiple copies of the behavior can be used to control more than one channel at a time). " & "The sprite used as the 'thumb' moves horizontally or vertically, with the right or top position being the maximum volume position. " & "The direction of movement is defined by the sprite chosen as a constraint. " & "The constraint sprite must be in a lower-numbered channel than the 'thumb', and it must be at least slightly larger than the 'thumb'. " & "A constraint sprite that is wider than it is tall will cause the 'thumb' to move horizontally; a taller constraint sprite creates a vertical movement. " & "The stage may also be used as a constraint (and is the default if the chosen constraint has been moved, deleted, or resized). " & "The sound volume ranges from silent (0) to maximum (255)." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "Graphics." & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Sound channel - determines which sound channel this slider controls." & RETURN & "* Constraining sprite - determines direction and distance of slider movement (setting of 0 uses stage for constraint)." & RETURN & "* Initial sound volume - volume used for sound channel when slider first appears."
  132. end
  133.